// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2010-5-13 14:29:06
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   AuthoritiesManagerDaoImpl.java

package com.stnet.service.enterprice.system;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.modules.commons.Pager;
import com.stnet.bases.BaseManagerDaoImpl;
import com.stnet.entity.Authorities;
import com.stnet.entity.AuthoritiesBean;
import com.stnet.entity.RolesAuthorities;
import com.stnet.front.enterprice.EpAuthorities;

// Referenced classes of package org.stnet.service.enterprice.system:
//            AuthoritiesManagerDao

public class AuthoritiesManagerDaoImpl extends BaseManagerDaoImpl
    implements AuthoritiesManagerDao
{

    public AuthoritiesManagerDaoImpl()
    {
    }

    public void addAuthorities(Authorities authorities)
    {
        authoritiesDao.save(authorities);
    }

    public void deleteAuthorities(Long id)
    {
        List ra = rolesAuthoritiesDao.findByAuthId(id);
        RolesAuthorities r;
        for(Iterator iterator = ra.iterator(); iterator.hasNext(); rolesAuthoritiesDao.delete(r))
            r = (RolesAuthorities)iterator.next();

        authoritiesDao.delete(id);
    }

    public Pager findAuthorities(int pageSize, int pageNo, String statu)
    {
        Pager pager = authoritiesDao.getObjectListByClass(pageSize, pageNo,  statu);
        return pager;
    }
    
    public Authorities getAuthorities(Long id)
    {
        return authoritiesDao.get(id);
    }

    public void updateAuthorities(Authorities authorities)
    {
        authoritiesDao.update(authorities);
    }

    public List findAuthorities()
    {
        List find = authoritiesDao.findAll();
        return find;
    }

    public boolean isNameUnique(String name, String orgName)
    {
        if(!name.equals(orgName))
            return authoritiesDao.isNameUnique(name);
        else
            return true;
    }

    public boolean isDisplayNameUnique(String displayName, String orgName)
    {
        if(!displayName.equals(orgName))
            return authoritiesDao.isDisplayNameUnique(displayName);
        else
            return true;
    }

    public List findEpAuthorities()
    {
        List epAuth = new ArrayList();
        int i = 0;
        EpAuthorities temp;
        for(Iterator iterator = authoritiesDao.findAuthoritiesByTypeId(Long.valueOf(0L)).iterator(); iterator.hasNext(); epAuth.add(temp))
        {
            Authorities ad = (Authorities)iterator.next();
            temp = new EpAuthorities();
            temp.setAuthorities(ad);
            temp.setAuthoritiesList(authoritiesDao.findAuthoritiesByTypeId(ad.getId()));
        }

        return epAuth;
    }
    
    public Authorities getByName(String name)
    {
    	return this.authoritiesDao.getByName(name);
    }
    
    public Pager findAuthoritiesByType(int pageSize, int pageNo,String state,String type){
    	return this.authoritiesDao.findAuthoritiesByType(pageSize,pageNo,state,type);
    }
    
    public List findAuthorities(String type,String salesDirect){
    	return this.authoritiesDao.findAuthorities(type,salesDirect);
    }
    
    public List<AuthoritiesBean> findAuthoritiesByRose(String type,String salesDirect,Long roseid){
    	return this.authoritiesDao.findAuthoritiesByRose(type, salesDirect, roseid);
    }
}